home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Frameworks / Sprocket Framework DR2 / Sprocket Framework / UGuide.cp < prev    next >
Text File  |  1996-06-15  |  3KB  |  151 lines

  1. /*
  2.  
  3.     File:        UGuide.cp
  4.     Project:    Sprocket Framework 1.1 (DR2), released 6/15/96
  5.     Contains:    Apple Guide utilities
  6.     To Do:        ?
  7.  
  8.     Sprocket Major Contributors:
  9.     ----------------------------
  10.     Dave Falkenburg, producer of Sprocket 1.0
  11.     Bill Hayden,     producer of Sprocket 1.1
  12.     Steve Sisak,     producer of the upcoming Sprocket 2.0
  13.     
  14.     Pete Alexander        Steve Falkenburg    Randy Thelen
  15.     Eric Berdahl        Nitin Ganatra        Chris K. Thomas
  16.     Marshall Clow        Dave Hershey        Leonard Rosenthal
  17.     Tim Craycroft        Dave Mark            Dean Yu
  18.     David denBoer        Gary Powell
  19.     Cameron Esfahani    Jon Summers            Apple Computer, Inc.
  20.         
  21.     Comments, Additions, or Corrections:
  22.     ------------------------------------
  23.     Bill Hayden, Nikol Software <nikol@codewell.com>
  24.  
  25. */
  26.  
  27. // If you remove this file from your project, you may safely remove the following files:
  28. //  AGFileLib68K
  29. //  AGFileLibPPC
  30. //  AppleGuideGlueLib.xcoff
  31.  
  32.  
  33. #ifndef __PROCESSES__
  34. #include <Processes.h>
  35. #endif
  36.  
  37. #include "Sprocket.h"
  38. #include "UString.h"
  39. #include "UGuide.h"
  40. #include "AGFile.h"
  41.  
  42.  
  43. static UInt32 gGuideRefNum;
  44.  
  45.  
  46.  
  47. static OSErr GetAppFileSpec(FSSpecPtr pFileSpec);
  48.  
  49.  
  50.  
  51. /*****************************************************************************/
  52.  
  53.  
  54.  
  55. OSErr OpenGuideFile(void)
  56. {
  57. #if qDebug
  58.     if (!gHasAppleGuide)
  59.         {
  60.         DebugMessage("\pApple Guide called, but not installed");
  61.         return paramErr;
  62.         }
  63. #endif
  64.  
  65.     return AGOpen(nil, 0, nil, &gGuideRefNum);
  66. }
  67.  
  68.  
  69.  
  70. /*****************************************************************************/
  71.  
  72.  
  73. // Guide file must be in the same folder as the application
  74.  
  75.  
  76. OSErr OpenGuideFileWithSearch(ConstStr255Param SearchString)
  77. {
  78.     FSSpec    fileSpec;
  79.     short    vRefNum;
  80.     long    dirID;
  81.     OSErr    result;
  82.     
  83. #if qDebug
  84.     if (!gHasAppleGuide)
  85.         {
  86.         DebugMessage("\pApple Guide called, but not installed");
  87.         return paramErr;
  88.         }
  89. #endif
  90.  
  91.     // Get the file spec for this application.
  92.  
  93.     result = GetAppFileSpec(&fileSpec);
  94.     
  95.     if (result == noErr)
  96.         {
  97.         vRefNum = fileSpec.vRefNum;
  98.         dirID = fileSpec.parID;
  99.         
  100.         // Use AGFileLib to get the file spec
  101.         // for the first guide file of guide type HELP.
  102.         
  103.         result = AGFileGetIndDB(vRefNum, dirID, kAGFileDBTypeHelp, false, 1, &fileSpec);
  104.         if(result==noErr)
  105.             {
  106.             // Open guide file resource fork.
  107.             
  108.             gGuideRefNum = FSpOpenResFile(&fileSpec, fsRdPerm);
  109.             if(gGuideRefNum != -1)
  110.                 {
  111.                 // Done with guide file.
  112.  
  113.                 (void) FSClose(gGuideRefNum);
  114.                 
  115.                 // Open guide file with search phrase.
  116.  
  117.                 if(SearchString[0] > 0)
  118.                     result = AGOpenWithSearch(&fileSpec, 0, nil,
  119.                                                 SearchString, &gGuideRefNum);
  120.                 }
  121.             }
  122.         }
  123.         
  124.     return result;
  125. }
  126.  
  127.  
  128.  
  129.  
  130. /*****************************************************************************/
  131.  
  132.  
  133.  
  134.  
  135. OSErr GetAppFileSpec(FSSpecPtr theFileSpec)
  136. {
  137.     ProcessSerialNumber    currentProcess;
  138.     ProcessInfoRec        infoRec;
  139.     OSErr                result;
  140.     
  141.     currentProcess.highLongOfPSN = 0;
  142.     currentProcess.lowLongOfPSN = kCurrentProcess;
  143.     infoRec.processInfoLength = sizeof(infoRec);
  144.     infoRec.processName = nil;
  145.     infoRec.processAppSpec = theFileSpec;
  146.     result = GetCurrentProcess(¤tProcess);
  147.     if(result == noErr)
  148.         result = GetProcessInformation(¤tProcess, &infoRec);
  149.     return result;
  150. }
  151.